package cn.tedu.carhome.controller;

import cn.tedu.carhome.ex.ServiceException;
import cn.tedu.carhome.mapper.SupplierMapper;
import cn.tedu.carhome.pojo.VO.SupplierVO;
import cn.tedu.carhome.pojo.dto.SupplierInsertDTO;
import cn.tedu.carhome.service.impl.SupplierService;
import cn.tedu.carhome.web.JsonResult;
import cn.tedu.carhome.web.State;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
@Slf4j
@RestController
@RequestMapping(produces = "application/json;charset=utf-8")
public class SupplierInsertController {
    @Autowired
    SupplierMapper supplierMapper;
    @Autowired
    SupplierService supplierService;

    @PostMapping("/supplier/insert")     //添加供应商
    public JsonResult<Void> SupplierInsert(@Validated @RequestBody SupplierInsertDTO supplierInsertDTO){
        System.out.println(supplierInsertDTO);
        log.info(supplierInsertDTO.toString());
        return supplierService.SupplierInsert(supplierInsertDTO);
    }

    @RequestMapping("/supplierByName/select")  //通过供应商名称查询供应商信息
    public JsonResult<SupplierVO> supplierByName(String name){
        log.info("***输入供应商名称显示供应商信息***输入值为"+name);
        return supplierService.supplierByName(name);
    }

   @RequestMapping("/supplier/select")     //供应商列表---查询供应商所有信息
    public JsonResult<List<SupplierVO>> supplierSelect(){
       return supplierService.supplierSelect();
   }
}
